import json
import unittest

from parameterized import parameterized

from pythonProject3.api.ihrm_login import login_basedata
import requests


def login_data():
    file= "H:\\pythonProject3\\pythonProject3\\data\\login.json"
    test_data=[]
    with open(file,encoding="utf-8") as f:
        json_data=json.load(f)
        for test_case in json_data:
            mobile=test_case.get("mobile")
            password=test_case.get("password")
            Content_type = test_case.get("Content-Type")
            success = test_case.get("success")
            code = test_case.get("code")
            message = test_case.get("message")
            # data = test_case.get("data")
            status_code = test_case.get("status_code")
            test_data.append((mobile,password,Content_type,success,code,message,status_code))
        print(test_data)
    return test_data

class Test_IHRM(unittest.TestCase):

    def setUp(self):
        self.login=login_basedata()
        self.session=requests.session()


    def tearDown(self):
        if self.session:
            self.session.close()

    @parameterized.expand(login_data())
    def test_ihrm(self,mobile,password,Content_type,success,code,message,status_code):
        response=self.login.login(self.session,mobile,password)
        print(response.json())
        self.assertIn(Content_type,response.headers.get("Content-Type"))
        self.assertEqual(success,response.json().get("success"))
        self.assertEqual(code,response.json().get("code"))
        self.assertEqual(message,response.json().get("message"))
        # self.assertEqual(data,response.json().get("data"))
        self.assertEqual(status_code,response.status_code)

